﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Data;
using MyPublisher.Administration.Commands;
using System.Windows.ApplicationFramework;
using System.Collections.ObjectModel;
using MyPublisher.Administration.Model;
using MyPublisher.Framework;
using MyPublisher.Administration.Views;

namespace MyPublisher.Administration.ViewModels
{
    public class LocationsViewModel : DocumentViewModel<Document>
    {
        public ICommand newCommand;
        public ObservableCollection<LocationType> LocationTypes { get; private set; }
        public LocationType SelectedLocationType { get; set; }

        public LocationsViewModel(IView view, string name)
            : base(view, name)
        {
            this.LocationTypes = new ObservableCollection<LocationType>();
            foreach (LocationType type in App.TypesFactory.LocationTypes)
            {
                this.LocationTypes.Add(type);
            }
            if (this.LocationTypes.Count>0)
                SelectedLocationType = this.LocationTypes[0];
        }

        public ICommand NewCommand
        {
            get
            {
                if (newCommand == null)
                {
                    newCommand = new DelegateCommand(New,CanNew);
                }
                return newCommand;
            }
        }

        private void New()
        {
            Location location = new Location()
            {
                //Address = ,
                //Identity,
                Type = SelectedLocationType
            };
        }

        private bool CanNew()
        {
            return SelectedLocationType != null;
        }

        private void Refresh()
        {
            this.InsertItems(App.EntityFactory.Locations);
            this.SelectFirst();
        }
    }
}
